//
//  OHA_TabBarViewController.m
//  OneHourArrvie
//
//  Created by Sunny on 16/12/9.
//  Copyright © 2016年 Sunny. All rights reserved.
//

#import "DDT_TabBarViewController.h"
#import "base_NavBaseViewController.h"
static NSString *const DDT_DiscoverVC = @"DDT_DiscoverViewController";
static NSString *const DDT_SpecialtyVC = @"DDT_SpecialtyViewController";
static NSString *const DDT_CommunityVC = @"DDT_CommunityViewController";
static NSString *const DDT_MineVC = @"DDT_MineViewController";

#define kClassKey @"rootVCClassString"
#define kTitleKey @"title"
#define kImageKey @"imageName"
#define kSelectimgKey @"selectedImageName"

static NSString *const DDT_Discover = @"发现";
static NSString *const DDT_Specialty = @"特产圈子";
static NSString *const DDT_Community = @"圈子";
static NSString *const DDT_Mine = @"我的";
@interface DDT_TabBarViewController ()

@end

@implementation DDT_TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSArray *childItemsArray = @[
                                 @{kClassKey:DDT_DiscoverVC,
                                   kTitleKey:DDT_Discover,
                                   kImageKey:@"tabbar_mainframe",
                                   kSelectimgKey:@"tabbar_mainframeHL"},
                                 @{kClassKey:DDT_SpecialtyVC,
                                   kTitleKey:DDT_Specialty,
                                   kImageKey:@"tabbar_contacts",
                                   kSelectimgKey:@"tabbar_contactsHL"
                                   },
                                 @{kClassKey:DDT_CommunityVC,
                                   kTitleKey:DDT_Community,
                                   kImageKey:@"tabbar_shopingcar",
                                   kSelectimgKey:@"tabbar_shopingcarHL"},
                                 @{kClassKey:DDT_MineVC,
                                   kTitleKey:DDT_Mine,
                                   kImageKey:@"tabbar_me",
                                   kSelectimgKey:@"tabbar_meHL"}
                                 
                                 ];
    
    [childItemsArray enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIViewController *vc = [NSClassFromString(obj[kClassKey])new];
        vc.title = obj[kTitleKey];
        base_NavBaseViewController *nav = [[base_NavBaseViewController alloc]initWithRootViewController:vc];
        UITabBarItem *item = nav.tabBarItem;
        item.title = obj[kTitleKey];
        item.image = [UIImage imageNamed:obj[kImageKey]];
        item.selectedImage = [[UIImage imageNamed:obj[kSelectimgKey]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]} forState:UIControlStateSelected];
        if ([obj[kTitleKey] isEqualToString:DDT_DiscoverVC]) {
            nav.navigationBar.translucent = YES;
        }
        [self addChildViewController:nav];
    }];
    self.selectedIndex = 0;
    self.delegate = self;

}

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
//    if ([viewController.title isEqualToString:@"购物车"]) {
//        //创建一个消息对象
//        NSNotification * notice = [NSNotification notificationWithName:@"ReloadTableView" object:nil userInfo:@{@"1":@"addInToCarReload"}];
//        //发送消息
//        [[NSNotificationCenter defaultCenter]postNotification:notice];
//    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
